import 'package:calendar_date_picker2/calendar_date_picker2.dart';
import 'package:flutter_pickers/more_pickers/init_data.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:flutter_pickers/style/picker_style.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:part_time_job_pro/common/index.dart';
import 'package:part_time_job_pro/common/widgets/custom_text_formater.dart';
import 'package:part_time_job_pro/common/widgets/rectangle_check_box.dart';

import 'logic.dart';

class PartDetailPage extends StatefulWidget {
  const PartDetailPage({Key? key}) : super(key: key);

  //路由地址
  static const String routeName = "/public/part/detail";

  @override
  State<PartDetailPage> createState() => PartDetailPageState();
}

class PartDetailPageState extends State<PartDetailPage> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    Get.delete<PartDetailLogic>();
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeMetrics() {
    //处理键盘收缩
    if (MediaQuery.of(context).viewInsets.bottom == 0) {
      state.isShowNextStepButton = true;
      logic.update();
    } else {
      state.isShowNextStepButton = false;
      logic.update();
    }
  }

  final logic = Get.find<PartDetailLogic>();
  final state = Get.find<PartDetailLogic>().state;
  final ScrollController scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PartDetailLogic>(builder: (logic) {
      return Scaffold(
          appBar: AppBar(
            backgroundColor: AppColor.norWhite01Color,
            leading: InkWell(
                onTap: () {
                  Get.back();
                },
                child: Container(
                  padding: EdgeInsets.all(0.r),
                  child: Image.asset(AssetsImages.appBarBack),
                )),
            elevation: 0,
            title: const Text(
              "完善职位要求",
              style: AppTheme.appBarStyle,
            ),
            actions: [
              Padding(
                  padding: const EdgeInsets.fromLTRB(0, 15, 15, 10),
                  child: Text(
                    "帮助文档",
                    style: TextStyle(fontSize: 14.r, color: AppColor.norBlue02Colors),
                  ))
            ],
          ),
          body: Stack(
            children: [
              GestureDetector(
                onTap: () {
                  CommonUtil.clearFocus();
                },
                child: Scrollbar(
                  thickness: state.scrollBarThickness,
                  controller: scrollController,
                  thumbVisibility: true,
                  trackVisibility: true,
                  child: SingleChildScrollView(
                    controller: scrollController,
                    child: Container(
                      width: 1.sw,
                      margin: EdgeInsets.only(bottom: 110.h, top: 4.h),
                      color: AppColor.norWhite01Color,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          buildJobSignUpCount(),
                          buildUserSexSelect(context),
                          buildSalaryAndAmount(),
                          buildWorkWelfare(),
                          buildWorkTypeSelect(),
                          state.workType == 1
                              ? buildTimeLimitSelect(context)
                              : SizedBox(
                                  height: 0.r,
                                ),
                          state.workType == 1
                              ? buildWeekDayLimitSelect(context)
                              : SizedBox(
                                  height: 0.r,
                                ),
                          state.workType == 0
                              ? buildWorkDateSelect()
                              : SizedBox(
                                  height: 0.r,
                                ),
                          buildWorkTimeSelect(),
                          buildContactEmail(),
                          buildContactPeople(),
                          buildContactMobile(),
                          buildAcceptAdvisory()
                        ],
                      ),
                    ),
                  ),
                ),
              ),
              Positioned(
                top: 0.h,
                left: 0.h,
                child: buildTopProgress(),
              ),
              Positioned(
                bottom: 0,
                left: 0,
                child: Visibility(visible: state.isShowNextStepButton, child: buildPreviewAndCreateButton()),
              )
            ],
          ));
    });
  }

  //处理的顶部进度条
  Widget buildTopProgress() {
    return Container(
      height: 4.h,
      width: 1.sw,
      color: AppColor.norWhite01Color,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Expanded(
            flex: 1,
            child: Container(
              height: 3.h,
              decoration: BoxDecoration(
                color: AppColor.norMainThemeColors,
                borderRadius: BorderRadius.only(
                  topRight: Radius.circular(4.r),
                  bottomRight: Radius.circular(4.r),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  //处理报名人数
  Widget buildJobSignUpCount() {
    return Container(
        padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 15.r),
        width: 1.sw,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              alignment: Alignment.centerLeft,
              width: formTitleWidth.w,
              child: const Text("报名人数", style: AppTheme.textTitleStyle),
            ),
            Container(
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: TextField(
                focusNode: logic.signUpCountFocusNode,
                keyboardType: TextInputType.number,
                keyboardAppearance: Brightness.light,
                autofocus: false,
                showCursor: true,
                cursorHeight: 16.sp,
                onChanged: (text) {
                  logic.updateSignUpCount(text);
                },
                inputFormatters: [
                  CustomTextInputFormatter.integerFormatter,
                ],
                cursorColor: AppColor.norMainThemeColors,
                controller: logic.signUpCountTextEditController,
                decoration: InputDecoration(
                    hintText: "请输入最大报名人数，招满岗位将自动下架",
                    border: InputBorder.none,
                    suffixIcon: state.signUpCount != 0 && logic.signUpCountFocusNode.hasFocus
                        ? IconButton(
                            color: AppColor.norGrayColor,
                            onPressed: () {
                              logic.clearSignUpCount();
                            },
                            icon: const Icon(Icons.cancel))
                        : SizedBox(
                            width: 0.r,
                          ),
                    hintStyle: TextStyle(
                      color: AppColor.norGrayColor,
                      fontSize: 13.sp,
                    )),
                style: TextStyle(fontSize: 13.sp, color: AppColor.norBlackColors),
              ),
            )
          ],
        ));
  }

  //处理性别选择
  Widget buildUserSexSelect(BuildContext context) {
    return Container(
        padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 20.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              alignment: Alignment.centerLeft,
              width: double.infinity,
              child: const Text("性别要求", style: AppTheme.textTitleStyle),
            ),
            Container(
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: Row(children: [
                Expanded(
                    child: InkWell(
                        onTap: () {
                          Pickers.showSinglePicker(context,
                              data: PickerDataType.sex,
                              pickerStyle: PickerStyle(
                                  textSize: 16.sp,
                                  title: Text(
                                    "性别选择",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        fontSize: 14.sp, fontWeight: FontWeight.w500, color: AppColor.norBlack01Colors),
                                  )),
                              selectData: "不限", onConfirm: (data, position) {
                            setState(() {
                              state.selectUserSex = data;
                            });
                          }, onChanged: (data, position) {
                            LogUtil.e(data);
                          });
                        },
                        child: Container(
                          padding: EdgeInsets.symmetric(vertical: 10.r),
                          margin: EdgeInsets.only(left: 0.r),
                          child: Text(
                            state.selectUserSex == "" ? "请选择" : state.selectUserSex,
                            style: TextStyle(
                                fontSize: 13.sp,
                                color: state.selectUserSex == "" ? AppColor.norGrayColor : AppColor.norBlackColors),
                          ),
                        ))),
                Container(
                    alignment: Alignment.centerRight,
                    width: 40.w,
                    child: Image.asset(
                      AssetsImages.rightArrow,
                      height: 14.h,
                    ))
              ]),
            ),
          ],
        ));
  }

  //处理时间要求选择
  Widget buildTimeLimitSelect(BuildContext context) {
    return Container(
        padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 20.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              alignment: Alignment.centerLeft,
              width: double.infinity,
              child: const Text("时间要求", style: AppTheme.textTitleStyle),
            ),
            Container(
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom: BorderSide(width: 1.r, color: const Color.fromRGBO(241, 242, 246, 1)),
                ),
              ),
              child: Row(children: [
                Expanded(
                    child: InkWell(
                        onTap: () {
                          Pickers.showSinglePicker(context,
                              data: state.workTimeLimitList.map((item) {
                                return item.dictLabel;
                              }).toList(),
                              pickerStyle: PickerStyle(
                                  textSize: 16.sp,
                                  title: Text(
                                    "时间要求",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        fontSize: 14.sp, fontWeight: FontWeight.w500, color: AppColor.norBlack01Colors),
                                  )),
                              selectData: state.workTimeLimitList[0].dictLabel, onConfirm: (data, position) {
                            setState(() {
                              state.selectWorkTimeLimit = data;
                            });
                          }, onChanged: (data, position) {
                            LogUtil.e(data);
                          });
                        },
                        child: Container(
                          padding: EdgeInsets.symmetric(vertical: 10.r),
                          margin: EdgeInsets.only(left: 0.r),
                          child: Text(
                            state.selectWorkTimeLimit == "" ? "请点击选择" : state.selectWorkTimeLimit,
                            style: TextStyle(
                                fontSize: 13.sp,
                                color:
                                    state.selectWorkTimeLimit == "" ? AppColor.norGrayColor : AppColor.norBlackColors),
                          ),
                        ))),
                Container(
                    alignment: Alignment.centerRight,
                    width: 40.w,
                    child: Image.asset(
                      AssetsImages.rightArrow,
                      height: 14.h,
                    ))
              ]),
            ),
          ],
        ));
  }

  //处理每周要求选择
  Widget buildWeekDayLimitSelect(BuildContext context) {
    return Container(
        padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 20.r),
        color: AppColor.norWhite01Color,
        width: 1.sw,
        child: Column(
          children: [
            Container(
              alignment: Alignment.centerLeft,
              width: double.infinity,
              child: const Text("每周至少", style: AppTheme.textTitleStyle),
            ),
            Container(
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: Row(children: [
                Expanded(
                    child: InkWell(
                        onTap: () {
                          Pickers.showSinglePicker(context,
                              data: state.weekWorkDayList.map((item) {
                                return item.dictLabel;
                              }).toList(),
                              pickerStyle: PickerStyle(
                                  textSize: 16.sp,
                                  title: Text(
                                    "上班要求",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        fontSize: 14.sp, fontWeight: FontWeight.w500, color: AppColor.norBlack01Colors),
                                  )),
                              selectData: state.weekWorkDayList[0].dictLabel, onConfirm: (data, position) {
                            setState(() {
                              state.selectWeekWorkDay = data;
                            });
                          }, onChanged: (data, position) {
                            LogUtil.e(data);
                          });
                        },
                        child: Container(
                          padding: EdgeInsets.symmetric(vertical: 10.r),
                          margin: EdgeInsets.only(left: 0.r),
                          child: Text(
                            state.selectWeekWorkDay == "" ? "请点击选择" : state.selectWeekWorkDay,
                            style: TextStyle(
                                fontSize: 13.sp,
                                color: state.selectWeekWorkDay == "" ? AppColor.norGrayColor : AppColor.norBlackColors),
                          ),
                        ))),
                Container(
                    alignment: Alignment.centerRight,
                    width: 40.w,
                    child: Image.asset(
                      AssetsImages.rightArrow,
                      height: 14.h,
                    ))
              ]),
            ),
          ],
        ));
  }

  //处理工资及结算部分
  Widget buildSalaryAndAmount() {
    return Container(
        margin: EdgeInsets.symmetric(horizontal: 20.w, vertical: 0.h),
        decoration: BoxDecoration(
          color: AppColor.norWhite01Color,
          border: Border(
            bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
          ),
        ),
        width: 1.sw,
        child: Row(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
          Expanded(
              flex: 1,
              child: Container(
                color: Colors.transparent,
                margin: EdgeInsets.symmetric(vertical: 5.h),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Container(
                        color: Colors.transparent,
                        width: (1.sw - 40.w) / 3,
                        child: Text(
                          "基本工资",
                          textAlign: TextAlign.left,
                          style:
                              TextStyle(fontSize: 14.sp, fontWeight: FontWeight.bold, color: AppColor.norBlack01Colors),
                        )),
                    Container(
                        color: Colors.transparent,
                        height: 30.h,
                        width: (1.sw - 40.w) / 3,
                        child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
                          Expanded(
                              child: Container(
                                  color: Colors.transparent,
                                  width: (1.sw - 40.w) / 3 - 30.w,
                                  child: TextField(
                                    focusNode: logic.salaryCountFocusNode,
                                    keyboardType: TextInputType.number,
                                    keyboardAppearance: Brightness.light,
                                    autofocus: false,
                                    showCursor: true,
                                    cursorHeight: 12.sp,
                                    inputFormatters: [
                                      CustomTextInputFormatter.numberFormatter(),
                                    ],
                                    onChanged: (text) {
                                      logic.updateSalaryCount(text);
                                    },
                                    cursorColor: AppColor.norMainThemeColors,
                                    controller: logic.salaryTextEditController,
                                    decoration: InputDecoration(
                                        hintText: "请输入薪酬",
                                        contentPadding: EdgeInsets.only(left: 5.w, right: 5.w, bottom: 3.h),
                                        border: InputBorder.none,
                                        hintStyle: TextStyle(
                                          color: AppColor.norGrayColor,
                                          fontSize: 12.sp,
                                        )),
                                    style: TextStyle(fontSize: 12.sp, color: AppColor.norBlackColors),
                                  ))),
                          Container(
                              width: 12.w,
                              color: Colors.transparent,
                              child: Text(
                                "元",
                                textAlign: TextAlign.right,
                                style: TextStyle(
                                    fontSize: 12.sp, fontWeight: FontWeight.bold, color: AppColor.norBlack01Colors),
                              ))
                        ])),
                  ],
                ),
              )),
          Expanded(
              flex: 1,
              child: Container(
                color: Colors.transparent,
                margin: EdgeInsets.symmetric(vertical: 5.h),
                child: Column(
                  children: [
                    Container(
                        color: Colors.transparent,
                        width: (1.sw - 40.w) / 3,
                        child: Text(
                          "工资单位",
                          textAlign: TextAlign.center,
                          style:
                              TextStyle(fontSize: 14.sp, fontWeight: FontWeight.bold, color: AppColor.norBlack01Colors),
                        )),
                    InkWell(
                        onTap: () {
                          Pickers.showSinglePicker(context,
                              data: state.salaryUnitList.map((item) {
                                return item.dictLabel;
                              }).toList(),
                              pickerStyle: PickerStyle(
                                  textSize: 16.sp,
                                  title: Text(
                                    "选择工资单位",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        fontSize: 14.sp, fontWeight: FontWeight.w500, color: AppColor.norBlack01Colors),
                                  )),
                              selectData: state.salaryUnitList[0].dictLabel, onConfirm: (data, position) {
                            setState(() {
                              state.selectSalaryUnit = data;
                            });
                          }, onChanged: (data, position) {
                            LogUtil.e(data);
                          });
                        },
                        child: Container(
                            color: Colors.transparent,
                            width: (1.sw - 40.w) / 3,
                            height: 30.h,
                            alignment: Alignment.center,
                            child: Text(
                              state.selectSalaryUnit.isEmpty ? "点击选择" : state.selectSalaryUnit,
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  fontSize: 12.sp,
                                  fontWeight: FontWeight.normal,
                                  color: state.selectSalaryUnit.isEmpty
                                      ? AppColor.norGray02Color
                                      : AppColor.norBlack01Colors),
                            ))),
                  ],
                ),
              )),
          Expanded(
              flex: 1,
              child: Container(
                color: Colors.transparent,
                margin: EdgeInsets.symmetric(vertical: 5.h),
                child: Column(
                  children: [
                    Container(
                        color: Colors.transparent,
                        width: (1.sw - 40.w) / 3,
                        child: Text(
                          "结算周期",
                          textAlign: TextAlign.center,
                          style:
                              TextStyle(fontSize: 14.sp, fontWeight: FontWeight.bold, color: AppColor.norBlack01Colors),
                        )),
                    InkWell(
                        onTap: () {
                          Pickers.showSinglePicker(context,
                              data: state.cashPeriodList.map((item) {
                                return item.dictLabel;
                              }).toList(),
                              pickerStyle: PickerStyle(
                                  textSize: 16.sp,
                                  title: Text(
                                    "选择结算周期",
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                        fontSize: 14.sp, fontWeight: FontWeight.w500, color: AppColor.norBlack01Colors),
                                  )),
                              selectData: state.cashPeriodList[0].dictLabel, onConfirm: (data, position) {
                            setState(() {
                              state.selectCashPeriod = data;
                            });
                          }, onChanged: (data, position) {
                            LogUtil.e(data);
                          });
                        },
                        child: Container(
                            color: Colors.transparent,
                            width: (1.sw - 40.w) / 3,
                            height: 30.h,
                            alignment: Alignment.center,
                            child: Text(
                              state.selectCashPeriod.isEmpty ? "点击选择" : state.selectCashPeriod,
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  fontSize: 12.sp,
                                  fontWeight: FontWeight.normal,
                                  color: state.selectCashPeriod.isEmpty
                                      ? AppColor.norGray02Color
                                      : AppColor.norBlack01Colors),
                            ))),
                  ],
                ),
              )),
        ]));
  }

  //处理工作种类
  Widget buildWorkTypeSelect() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 20.w, vertical: 5.h),
      padding: EdgeInsets.only(bottom: 15.h),
      width: 1.sw,
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
        ),
      ),
      child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
        Container(
          width: 70.r,
          alignment: Alignment.centerLeft,
          child: const Text("工作种类", textAlign: TextAlign.end, style: AppTheme.textTitleStyle),
        ),
        Expanded(
            flex: 1,
            child: Container(
              alignment: Alignment.centerLeft,
              width: formTitleWidth.w,
              padding: EdgeInsets.only(left: 0.r),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  GestureDetector(
                      onTap: () {
                        logic.changeWorkType(0);
                      },
                      child: Container(
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 35.r),
                        margin: EdgeInsets.only(left: 5.r),
                        decoration: BoxDecoration(
                            color: state.workType == 0 ? AppColor.norMainThemeColors : AppColor.norWhite01Color,
                            border: Border.all(
                              width: 0.2.r,
                              color: state.workType == 0 ? AppColor.norMainThemeColors : AppColor.norBlack01Colors,
                            ),
                            borderRadius: BorderRadius.circular(4)),
                        child: Text("短招",
                            style: TextStyle(
                                color: state.workType == 0 ? AppColor.norWhite01Color : AppColor.norMainThemeColors,
                                fontSize: 13.sp)),
                      )),
                  GestureDetector(
                      onTap: () {
                        logic.changeWorkType(1);
                      },
                      child: Container(
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 35.r),
                        margin: EdgeInsets.only(left: 5.r),
                        decoration: BoxDecoration(
                            color: state.workType == 1 ? AppColor.norMainThemeColors : AppColor.norWhite01Color,
                            border: Border.all(
                              width: 0.2.r,
                              color: state.workType == 1 ? AppColor.norMainThemeColors : AppColor.norBlack01Colors,
                            ),
                            borderRadius: BorderRadius.circular(4)),
                        child: Text("长招",
                            style: TextStyle(
                                color: state.workType == 1 ? AppColor.norWhite01Color : AppColor.norBlack01Colors,
                                fontSize: 13.sp)),
                      ))
                ],
              ),
            )),
      ]),
    );
  }

  //处理工作福利
  Widget buildWorkWelfare() {
    return Container(
        padding: EdgeInsets.fromLTRB(20.w, 15.h, 20.w, 10.h),
        width: 1.sw,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              alignment: Alignment.centerLeft,
              child: const Text("工作福利(可多选)", style: AppTheme.textTitleStyle),
            ),
            Container(
              decoration: BoxDecoration(
                color: Colors.transparent,
                border: Border(
                  bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: state.workWelfareList.isNotEmpty
                  ? buildWorkWelfareGrid()
                  : SizedBox(
                      height: 0.r,
                    ),
            )
          ],
        ));
  }

  Widget buildWorkWelfareGrid() {
    return Container(
      width: 1.sw,
      height: 100.h,
      padding: EdgeInsets.only(top: 5.h, bottom: 0.h),
      child: GridView.builder(
        physics: const ScrollPhysics(),
        primary: false,
        shrinkWrap: true,
        scrollDirection: Axis.vertical,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3, mainAxisSpacing: 4.r, crossAxisSpacing: 4.r, childAspectRatio: 2.75),
        itemCount: state.workWelfareList.length,
        itemBuilder: (context, index) {
          return buildWelfareGridItem(state.workWelfareList[index]);
        },
      ),
    );
  }

  //处理单个选项
  buildWelfareGridItem(SysDictData welfare) {
    return GestureDetector(
        onTap: () {
          welfare.checked = !welfare.checked;
          logic.update();
        },
        child: Container(
          alignment: Alignment.center,
          margin: EdgeInsets.only(right: 5.r, bottom: 0.r, top: 5.r),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(4.r),
            border: Border.all(
                width: welfare.checked ? 0.5 : 0.3,
                color: welfare.checked ? AppColor.norMainThemeColors : AppColor.norGray02Color),
            color: welfare.checked ? AppColor.norMainThemeColors : AppColor.norWhiteColor,
          ),
          child: Text(
            welfare.dictLabel ?? "",
            style: TextStyle(
                fontSize: 11.r,
                fontWeight: FontWeight.w500,
                color: welfare.checked ? AppColor.norWhite01Color : AppColor.norBlackColors),
          ),
        ));
  }

  //选择工作日期
  showWorkDateSelect() async {
    var results = await showCalendarDatePicker2Dialog(
      context: context,
      config: CalendarDatePicker2WithActionButtonsConfig(
          calendarType: CalendarDatePicker2Type.range,
          disableModePicker: false,
          weekdayLabelTextStyle: TextStyle(
            color: AppColor.norBlack01Colors,
            fontSize: 12.sp,
            fontWeight: FontWeight.w500,
          ),
          centerAlignModePicker: true,
          firstDate: state.initDate,
          gapBetweenCalendarAndButtons: 0,
          okButton: Text(
            "确定",
            style: TextStyle(fontSize: 13.sp, color: AppColor.norMainThemeColors, fontWeight: FontWeight.w500),
          ),
          cancelButton: Text(
            "取消",
            style: TextStyle(fontSize: 13.sp, color: AppColor.norMainThemeColors, fontWeight: FontWeight.w500),
          )),
      dialogSize: const Size(300, 320),
      value: [state.initDate],
      borderRadius: BorderRadius.circular(15),
    );
    if (results != null) {
      logic.submitWorkDate(results.cast<DateTime>());
    }
  }

  //选择上班时间
  showWorkTimeSelect() {
    final today = DateUtils.dateOnly(DateTime.now());
    LogUtil.e(today, tag: "today");
    showDialog(
      context: context,
      useRootNavigator: true,
      useSafeArea: true,
      barrierDismissible: false,
      barrierColor: Colors.black45,
      builder: (context) => GetBuilder<PartDetailLogic>(
          builder: (logic) => Dialog(
                backgroundColor: Colors.white,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(10),
                ),
                child: Container(
                    width: 280.w,
                    height: 210.h,
                    padding: EdgeInsets.all(0.r),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Container(
                                height: 25.h,
                                width: 140.w,
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                    color: AppColor.norWhite10Color,
                                    borderRadius: BorderRadius.only(topLeft: Radius.circular(10.r))),
                                child: Text(
                                  "开始",
                                  style: TextStyle(
                                      fontWeight: FontWeight.w500, fontSize: 13.sp, color: AppColor.norBlack01Colors),
                                )),
                            Container(
                                height: 25.h,
                                width: 140.w,
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                    color: AppColor.norWhite06Color,
                                    borderRadius: BorderRadius.only(topRight: Radius.circular(10.r))),
                                child: Text(
                                  "结束",
                                  style: TextStyle(
                                      fontWeight: FontWeight.w500, fontSize: 13.sp, color: AppColor.norBlack01Colors),
                                )),
                          ],
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Container(
                                color: AppColor.norWhite10Color,
                                height: 150.h,
                                width: 140.w,
                                child: ScrollConfiguration(
                                    behavior: const ScrollBehavior(),
                                    child: CupertinoDatePicker(
                                      key: UniqueKey(),
                                      initialDateTime: state.initStartTime,
                                      mode: CupertinoDatePickerMode.time,
                                      use24hFormat: true,
                                      minuteInterval: 15,
                                      onDateTimeChanged: (value) {
                                        logic.changeStartWorkTime(value);
                                      },
                                    ))),
                            Container(
                                color: AppColor.norWhite06Color,
                                height: 150.h,
                                width: 140.w,
                                child: ScrollConfiguration(
                                    behavior: const ScrollBehavior(),
                                    child: CupertinoDatePicker(
                                      key: UniqueKey(),
                                      initialDateTime: state.initEndTime,
                                      mode: CupertinoDatePickerMode.time,
                                      use24hFormat: true,
                                      minuteInterval: 15,
                                      onDateTimeChanged: (value) {
                                        logic.changeEndWorkTime(value);
                                      },
                                    )))
                          ],
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            InkWell(
                                onTap: () {
                                  logic.submitWorkTime();
                                },
                                child: Container(
                                    color: Colors.transparent,
                                    height: 35.h,
                                    width: 140.w,
                                    alignment: Alignment.center,
                                    child: Text(
                                      "确定",
                                      style: TextStyle(
                                          fontWeight: FontWeight.w500,
                                          fontSize: 13.sp,
                                          color: AppColor.norBlack01Colors),
                                    ))),
                            InkWell(
                                onTap: () {
                                  logic.closeTimeSelect();
                                },
                                child: Container(
                                    color: Colors.transparent,
                                    height: 35.h,
                                    width: 140.w,
                                    alignment: Alignment.center,
                                    child: Text(
                                      "取消",
                                      style: TextStyle(
                                          fontWeight: FontWeight.w500,
                                          fontSize: 13.sp,
                                          color: AppColor.norBlack01Colors),
                                    ))),
                          ],
                        ),
                      ],
                    )),
              )),
    );
  }

  //处理工作日期
  Widget buildWorkDateSelect() {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 15.r, horizontal: 20.r),
      margin: EdgeInsets.only(bottom: 10.r),
      width: 1.sw,
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
        ),
      ),
      child: Row(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [
        Container(
          width: 70.r,
          alignment: Alignment.centerLeft,
          child: const Text("工作日期", textAlign: TextAlign.end, style: AppTheme.textTitleStyle),
        ),
        Container(
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.only(left: 10.r),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: getWorkDateItemList(),
          ),
        ),
      ]),
    );
  }

  //处理工作日期列表
  List<Widget> getWorkDateItemList() {
    List<Widget> workDateItemList = [];
    if (state.workDateList.isNotEmpty) {
      workDateItemList.addAll(state.workDateList.map((workDate) {
        return GestureDetector(
            onTap: () {},
            child: Container(
              alignment: Alignment.center,
              //width: 110.w,
              padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 10.r),
              margin: EdgeInsets.only(left: 0.r, bottom: 5.r),
              decoration: BoxDecoration(
                  color: AppColor.norGray07Color,
                  border: Border.all(
                    width: 0.5.r,
                    color: AppColor.norGray07Color,
                  ),
                  borderRadius: BorderRadius.circular(4)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(workDate.replaceAll("#", "至"),
                      style: TextStyle(color: AppColor.norBlack01Colors, fontSize: 11.sp)),
                  SizedBox(
                    width: 4.r,
                  ),
                  Image.asset(
                    AssetsImages.closeIcon2,
                    height: 16,
                  ),
                ],
              ),
            ));
      }).toList());
    }
    //加入按钮
    workDateItemList.add(GestureDetector(
        onTap: () {
          showWorkDateSelect();
        },
        child: Container(
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 12.r),
          margin: EdgeInsets.only(left: 0.r),
          decoration: BoxDecoration(
              color: AppColor.norMainThemeColors,
              border: Border.all(width: 0.2.r, color: AppColor.norMainThemeColors),
              borderRadius: BorderRadius.circular(4)),
          child: Text("＋添加工作日期", style: TextStyle(color: AppColor.norWhite01Color, fontSize: 12.sp)),
        )));
    return workDateItemList;
  }

  //处理上班时间列表
  List<Widget> getWorkTimeItemList() {
    List<Widget> workTimeItemList = [];
    if (state.workTimeList.isNotEmpty) {
      workTimeItemList.addAll(state.workTimeList.map((workTime) {
        return GestureDetector(
            onTap: () {
              logic.removerWorkTime(workTime);
            },
            child: Container(
              alignment: Alignment.center,
              width: 110.w,
              padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 0.r),
              margin: EdgeInsets.only(left: 0.r, bottom: 5.r),
              decoration: BoxDecoration(
                  color: AppColor.norGray07Color,
                  border: Border.all(
                    width: 0.5.r,
                    color: AppColor.norGray07Color,
                  ),
                  borderRadius: BorderRadius.circular(4)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(workTime.replaceAll("-", "至"),
                      style: TextStyle(color: AppColor.norBlack01Colors, fontSize: 11.sp)),
                  SizedBox(
                    width: 4.r,
                  ),
                  Image.asset(
                    AssetsImages.closeIcon2,
                    height: 16,
                  ),
                ],
              ),
            ));
      }).toList());
    }
    //加入按钮
    workTimeItemList.add(GestureDetector(
        onTap: () {
          showWorkTimeSelect();
        },
        child: Container(
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 12.r),
          margin: EdgeInsets.only(left: 0.r),
          decoration: BoxDecoration(
              color: AppColor.norMainThemeColors,
              border: Border.all(width: 0.2.r, color: AppColor.norMainThemeColors),
              borderRadius: BorderRadius.circular(4)),
          child: Text("＋添加上班时间", style: TextStyle(color: AppColor.norWhite01Color, fontSize: 12.sp)),
        )));
    return workTimeItemList;
  }

  //处理工作时间
  Widget buildWorkTimeSelect() {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 15.r, horizontal: 20.r),
      margin: EdgeInsets.only(bottom: 10.r),
      width: 1.sw,
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
        ),
      ),
      child: Row(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [
        Container(
          width: 70.r,
          alignment: Alignment.centerLeft,
          child: const Text("上班时段", textAlign: TextAlign.end, style: AppTheme.textTitleStyle),
        ),
        Container(
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.only(left: 10.r),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: getWorkTimeItemList(),
          ),
        ),
      ]),
    );
  }

  //处理联系邮箱
  Widget buildContactEmail() {
    return Container(
        padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 15.r),
        width: 1.sw,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              alignment: Alignment.centerLeft,
              width: formTitleWidth.w,
              child: const Text("联系邮箱", style: AppTheme.textTitleStyle),
            ),
            Container(
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: TextField(
                focusNode: logic.emailFocusNode,
                keyboardType: TextInputType.emailAddress,
                keyboardAppearance: Brightness.light,
                autofocus: true,
                showCursor: true,
                cursorHeight: 16.sp,
                onChanged: (text) {
                  logic.updateEmail(text);
                },
                cursorColor: AppColor.norMainThemeColors,
                controller: logic.emailTextEditController,
                decoration: InputDecoration(
                    hintText: "请输入接收简历的邮箱",
                    border: InputBorder.none,
                    suffixIcon: state.emailText.isNotEmpty && logic.emailFocusNode.hasFocus
                        ? IconButton(
                            color: AppColor.norGrayColor,
                            onPressed: () {
                              logic.clearEmail();
                            },
                            icon: const Icon(Icons.cancel))
                        : SizedBox(
                            width: 0.r,
                          ),
                    hintStyle: TextStyle(
                      color: AppColor.norGrayColor,
                      fontSize: 14.sp,
                    )),
                style: TextStyle(fontSize: 13.sp, color: AppColor.norBlackColors),
              ),
            )
          ],
        ));
  }

  //处理联系人
  Widget buildContactPeople() {
    return Container(
        padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 15.r),
        width: 1.sw,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              alignment: Alignment.centerLeft,
              width: formTitleWidth.w,
              child: const Text("联系人", style: AppTheme.textTitleStyle),
            ),
            Container(
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: TextField(
                focusNode: logic.contactFocusNode,
                keyboardType: TextInputType.text,
                keyboardAppearance: Brightness.light,
                autofocus: true,
                showCursor: true,
                cursorHeight: 16.sp,
                onChanged: (text) {
                  logic.updateContactName(text);
                },
                cursorColor: AppColor.norMainThemeColors,
                controller: logic.contactTextEditController,
                decoration: InputDecoration(
                    hintText: "请输入联系称呼",
                    border: InputBorder.none,
                    suffixIcon: state.contactName.isNotEmpty && logic.contactFocusNode.hasFocus
                        ? IconButton(
                            color: AppColor.norGrayColor,
                            onPressed: () {
                              logic.clearContactName();
                            },
                            icon: const Icon(Icons.cancel))
                        : SizedBox(
                            width: 0.r,
                          ),
                    hintStyle: TextStyle(
                      color: AppColor.norGrayColor,
                      fontSize: 14.sp,
                    )),
                style: TextStyle(fontSize: 13.sp, color: AppColor.norBlackColors),
              ),
            )
          ],
        ));
  }

  //处理联系电话
  Widget buildContactMobile() {
    return Container(
        padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 15.r),
        width: 1.sw,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              alignment: Alignment.centerLeft,
              width: formTitleWidth.w,
              child: const Text("联系电话", style: AppTheme.textTitleStyle),
            ),
            Container(
              decoration: BoxDecoration(
                color: AppColor.norWhite01Color,
                border: Border(
                  bottom: BorderSide(width: 1.r, color: AppColor.norWhite06Color),
                ),
              ),
              child: TextField(
                focusNode: logic.mobileFocusNode,
                keyboardType: TextInputType.phone,
                keyboardAppearance: Brightness.light,
                autofocus: true,
                showCursor: true,
                cursorHeight: 16.sp,
                onChanged: (text) {
                  logic.updateTel(text);
                },
                cursorColor: AppColor.norMainThemeColors,
                controller: logic.mobileTextEditController,
                decoration: InputDecoration(
                    hintText: "请输入联系人号码",
                    border: InputBorder.none,
                    suffixIcon: state.mobileText.isNotEmpty && logic.mobileFocusNode.hasFocus
                        ? IconButton(
                            color: AppColor.norGrayColor,
                            onPressed: () {
                              logic.clearTel();
                            },
                            icon: const Icon(Icons.cancel))
                        : SizedBox(
                            width: 0.r,
                          ),
                    hintStyle: TextStyle(
                      color: AppColor.norGrayColor,
                      fontSize: 14.sp,
                    )),
                style: TextStyle(fontSize: 13.sp, color: AppColor.norBlackColors),
              ),
            )
          ],
        ));
  }

  //处理电话咨询部分
  Widget buildAcceptAdvisory() {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 15.r),
      width: 1.sw,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          GestureDetector(
            //checkbox
            onTap: () {
              logic.changeIsAcceptMobileCall();
            },
            child: Text.rich(
              //实现换行
              TextSpan(
                children: [
                  WidgetSpan(
                    child: RectangleCheckBox(
                      size: 14.sp,
                      animationDuration: const Duration(milliseconds: 300),
                      checkedColor: AppColor.norMainThemeColors,
                      borderColor: state.isAcceptMobileCall ? AppColor.norMainThemeColors : AppColor.norGrayColor,
                      isChecked: state.isAcceptMobileCall,
                      onTap: (value) {
                        logic.changeIsAcceptMobileCall();
                      },
                    ),
                  ),
                  TextSpan(
                    text: " ",
                    style: TextStyle(fontSize: 12.sp),
                  ),
                  TextSpan(
                    text: "接受电话咨询",
                    style: TextStyle(color: AppColor.norBlack01Colors, fontSize: 12.sp),
                  ),
                ],
              ),
            ),
          ),
          Visibility(
              visible: state.isAcceptMobileCall,
              child: Container(
                padding: EdgeInsets.only(top: 5.r),
                alignment: Alignment.centerLeft,
                child: Text("风险提醒，接受电话咨询有可能会被中介骚扰!",
                    style: TextStyle(fontWeight: FontWeight.normal, fontSize: 10.sp, color: AppColor.norRedColors)),
              )),
        ],
      ),
    );
  }

  //底部预览和创建岗位按钮
  Widget buildPreviewAndCreateButton() {
    return Container(
      width: 1.sw,
      decoration: BoxDecoration(
        color: AppColor.norWhite01Color,
        boxShadow: [
          BoxShadow(blurRadius: 1.w, spreadRadius: 1.w, color: AppColor.norWhite01Color),
          BoxShadow(blurRadius: 3.w, spreadRadius: 3.w, color: AppColor.norGray01Color)
        ],
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              GestureDetector(
                  onTap: () {
                    //预览数据
                  },
                  child: Container(
                    width: 90.w,
                    height: 35.h,
                    alignment: Alignment.center,
                    margin: EdgeInsets.fromLTRB(15.w, 10.r, 0, 10.r),
                    decoration: BoxDecoration(
                        color: AppColor.norWhite01Color,
                        border: Border.all(width: 0.5.r, color: AppColor.norMainThemeColors),
                        borderRadius: BorderRadius.circular(6)),
                    child: Text("预览", style: TextStyle(color: AppColor.norMainThemeColors, fontSize: 16.sp)),
                  )),
              Expanded(
                flex: 1,
                child: GestureDetector(
                    onTap: () {
                      //提交保存
                      CommonUtil.clearFocus();
                      logic.submitPartTimeJob();
                    },
                    child: Container(
                      height: 35.h,
                      alignment: Alignment.center,
                      margin: EdgeInsets.fromLTRB(10.r, 10.r, 15.r, 10.r),
                      decoration:
                          BoxDecoration(color: AppColor.norMainThemeColors, borderRadius: BorderRadius.circular(6)),
                      child: Text("创建岗位", style: TextStyle(color: AppColor.norWhite01Color, fontSize: 16.sp)),
                    )),
              )
            ],
          ),
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.fromLTRB(10.w, 0.h, 10.w, 20.h),
            decoration: BoxDecoration(color: Colors.transparent, borderRadius: BorderRadius.circular(6)),
            child: Text.rich(
              //实现换行
              TextSpan(
                children: [
                  TextSpan(
                    text: "创建岗位即表示您已仔细阅读并同意",
                    style: TextStyle(fontSize: 12.sp, color: AppColor.norBlack01Colors),
                  ),
                  TextSpan(
                    text: "《兼职帮发布职位协议》",
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        //Get.toNamed(AgreementPage.routeName);
                      },
                    style: TextStyle(color: AppColor.norBlue02Colors, fontSize: 12.sp),
                  ),
                  TextSpan(
                    text: "、",
                    style: TextStyle(fontSize: 12.sp, color: AppColor.norBlack01Colors),
                  ),
                  TextSpan(
                    text: "《中华人民共和国劳动合同法》",
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        //Get.toNamed(AgreementPage.routeName);
                      },
                    style: TextStyle(color: AppColor.norBlue02Colors, fontSize: 12.sp),
                  ),
                  TextSpan(
                    text: "和",
                    style: TextStyle(fontSize: 12.sp, color: AppColor.norBlack01Colors),
                  ),
                  TextSpan(
                    text: "《岗位发布规则与协议》",
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        //Get.toNamed(AgreementPage.routeName);
                      },
                    style: TextStyle(color: AppColor.norBlue02Colors, fontSize: 12.sp),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
